<template>
	<view class="">
		<u-navbar title="学生列表" bgColor="transparent" :autoBack="true" :fixed="false"></u-navbar>
		<view class="p-30" v-if="!noData">
			<navigator url="/pages/monitor/detail" class="card p-30 mt-30 flex-row justify-between align-center"
				v-for="(item,index) in 6">
				<view class="basis-xs flex-sub">
					<u-avatar size="40"></u-avatar>
				</view>
				<view class="gray-color small-size flex-twice">
					<view class="">
						姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：豆包
					</view>
					<view class="mt-10">
						年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄：8岁
					</view>
				</view>
				<view class="gray-color small-size flex-twice">
					<view class="">
						性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：男
					</view>
					<view class="mt-10">
						所在班级：小二班
					</view>
				</view>

			</navigator>
		</view>
		<template v-else>
			<u-empty marginTop="60" mode="data">
			</u-empty>
		</template>
		<page-tabbar :value="2" />
	</view>
</template>

<script>
	import {
		studentList
	} from '@/common/api.js'
	import commonMixin from '@/mixins/common.js';
	export default {
		mixins: [commonMixin],
		data() {
			return {
				status: 'loading',
				list: [],
				noData: false,
				page: 1,
				total: 0,

				banji_id: 0
			}
		},
		onLoad(e) {
			this.banji_id = e.banji_id
			this.init()
		},
		methods: {
			init() {
				this.status = "loading";
				this.list = [];
				this.page = 1;
				this.noData = false;
				this.getList();
			},
			getList() {
				let vm = this;
				let params = {
					'page': this.page,
					'limit': this.$u.config.limit,
					'banji_id': this.banji_id
				};
				studentList({
					params
				}).then(res => {
					console.log(res.rows.length);
					if (res.rows.length != 0) {
						this.noData = false;
						this.list = this.list.concat(res.rows);
						this.total = res.total;
						this.page++;
						this.status = "loadmore"
					} else {
						this.noData = true;
						this.status = "nomore"
					}
				}).catch(err => {
					vm.$refs.uToast.show({
						type: 'error',
						message: err.message,
						complete() {
							vm.loading = false;
						}
					})
				})
			},
			//上拉
			onPullDownRefresh() {
				this.status = "loading"
				this.init();
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 500);
			},
			//下拉
			onReachBottom() {
				let vm = this;
				this.status = 'loading';
				//延时为了看效果
				setTimeout(() => {
					if (vm.page > Math.ceil(vm.total / this.$u.config.limit)) {
						this.status = 'nomore';
					} else {
						vm.getList();
					}
				}, 200)
			}
		}
	}
</script>


<style>
</style>